package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.CategoryService;
import com.yexiao.cofe.common.annotation.PermissionController;
import com.yexiao.cofe.constant.PermissionConstant;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/listAll")
    public ResponseData listAll() {
        return ResponseData.success(categoryService.listAll());
    }

    @PostMapping("/add")
    public ResponseData add(@RequestBody JSONObject param, @IRequestToken String token) {
        categoryService.addCategory(param);
        return ResponseData.success();
    }

    @GetMapping("/del")
    public ResponseData delete(@IRequestParam JSONObject param, @IRequestToken String token) {
        categoryService.deleteCategory(param);
        return ResponseData.success();
    }

    @PostMapping("/modify")
    public ResponseData modify(@RequestBody JSONObject param, @IRequestToken String token) {
        categoryService.modifyCategory(param);
        return ResponseData.success();
    }
}
